package com.briup.cms.web.controller;

import com.briup.cms.bean.Comment;
import com.briup.cms.service.ICommentService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 * @version 1.0
 * @Description
 * @date 2021/7/17 21:18
 */

@Api(tags = "评论管理模块相关接口")
@RestController
@RequestMapping("/auth/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    @ApiOperation(value = "分页所有评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "keywords", value = "评论关键字", paramType = "query"),
    })
    @GetMapping("/pageQuery")
    public Message pageQuery(int pageNum, int pageSize, String keywords) {
        PageInfo<Comment> data = commentService.pageQuery(pageNum, pageSize, keywords);
        return MessageUtil.success(data);
    }


    @ApiOperation(value="批量删除评论")
    @DeleteMapping(value="/batchDelete")
    public Message batchDelete(int[] ids) {
        commentService.batchDelete(ids);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value="根据ID删除评论")
    @DeleteMapping(value="/deleteById")
    public Message deleteById(int id) {
        commentService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value="审核评论",notes="status状态：0-待审核，1-不通过，2-通过")
    @PutMapping(value="/check")
    public Message check(int id,int status) {
        commentService.checkComment(id, status);
        return MessageUtil.success("操作成功");
    }
    @ApiOperation(value="更新或保存评论")
    @PostMapping("saveOrUpdate")
    public  Message saveOrUpdate(Comment comment){
        commentService.saveOrUpdate(comment);
        return MessageUtil.success("操作成功");
    }
}
